package com.zhangshujie.ShoppingSystem;

import java.util.ArrayList;
import java.util.List;

public class Customer extends User {
    private String registrationTime;
    private double totalConsumption;
    private String level;
    private ShoppingCart cart;
    private List<String> shoppingHistory;

    public Customer(String id, String username, String password, String phoneNumber, String email, String registrationTime) {
        super(id, username, password, phoneNumber, email);
        this.registrationTime = registrationTime;
        this.totalConsumption = 0.0;
        this.level = "普通用户";
        this.cart = new ShoppingCart();
        this.shoppingHistory = new ArrayList<>();
    }

    public String getRegistrationTime() {
        return registrationTime;
    }

    public double getTotalConsumption() {
        return totalConsumption;
    }

    public String getLevel() {
        return level;
    }

    public ShoppingCart getCart() {
        return cart;
    }

    public List<String> getShoppingHistory() {
        return shoppingHistory;
    }

    @Override
    public void changePassword(String newPassword) {
        this.password = newPassword;
        System.out.println("客户密码修改成功！");
    }

    public String getPassword() {
        return password;
    }



    public void addToCart(Product product, int quantity) {
        cart.addProduct(product, quantity);
        System.out.println("商品已加入购物车！");
    }

    public void removeFromCart(Product product) {
        cart.removeProduct(product);
        System.out.println("商品已从购物车移除！");
    }

    public void updateCart(Product product, int quantity) {
        cart.updateProductQuantity(product, quantity);
        System.out.println("购物车已更新！");
    }

    public void checkout(String paymentMethod) {
        // 模拟支付逻辑
        double totalAmount = cart.calculateTotal();
        totalConsumption += totalAmount;
        shoppingHistory.add(STR."购买时间: \{java.time.LocalDateTime.now()}, 总金额: \{totalAmount}");
        cart.clear();
        System.out.println(STR."结账成功！支付方式: \{paymentMethod}");
    }

    @Override
    public String toString() {
        return STR."\{id},\{username},\{password},\{phoneNumber},\{email},\{registrationTime}";
    }
}
